namespace Home.Domain.Migrations
{
    using System.Data.Entity.Migrations;
    
    public partial class InitialCreate : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "Company",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Title = c.String(nullable: false, maxLength: 50),
                        Body = c.String(nullable: false),
                        CreateDate = c.DateTime(nullable: false),
                        Sort = c.Int(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "News",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Title = c.String(nullable: false, maxLength: 50),
                        Body = c.String(nullable: false),
                        CreateDate = c.DateTime(nullable: false),
                        PNewsId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("PNews", t => t.PNewsId, cascadeDelete: true)
                .Index(t => t.PNewsId);
            
            CreateTable(
                "PNews",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Title = c.String(nullable: false),
                        Sort = c.Int(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "Category",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 50),
                        CreateDate = c.DateTime(),
                        Sort = c.Int(),
                        State = c.Int(),
                        ParentId = c.Int(),
                        Path = c.String(maxLength: 50),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("Category", t => t.ParentId)
                .Index(t => t.ParentId);
            
            CreateTable(
                "Category_Brand",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        CategoryId = c.Int(),
                        BrandId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("Category", t => t.CategoryId)
                .ForeignKey("Brand", t => t.BrandId)
                .Index(t => t.CategoryId)
                .Index(t => t.BrandId);
            
            CreateTable(
                "Brand",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 50),
                        Sort = c.Int(),
                        CreateDate = c.DateTime(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "Quote",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        CreateDate = c.DateTime(),
                        SubmitDate = c.DateTime(),
                        State = c.Int(),
                        CategoryId = c.Int(),
                        BrandId = c.Int(),
                        QuoteProductId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("Category", t => t.CategoryId)
                .ForeignKey("Brand", t => t.BrandId)
                .Index(t => t.CategoryId)
                .Index(t => t.BrandId);
            
            CreateTable(
                "QuoteProduct",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ProductName = c.String(nullable: false, maxLength: 20),
                        Description = c.String(maxLength: 50),
                        Price = c.Decimal(nullable: false, precision: 18, scale: 2),
                        QuoteId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("Quote", t => t.QuoteId)
                .Index(t => t.QuoteId);
            
            CreateTable(
                "Product",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 50),
                        Price = c.Decimal(nullable: false, precision: 18, scale: 2),
                        Description = c.String(maxLength: 50),
                        Pic = c.String(maxLength: 50),
                        CreateDate = c.DateTime(),
                        CategoryId = c.Int(),
                        BrandId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("Category", t => t.CategoryId)
                .ForeignKey("Brand", t => t.BrandId)
                .Index(t => t.CategoryId)
                .Index(t => t.BrandId);
            
            CreateTable(
                "ProductPrice",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Price = c.Decimal(precision: 18, scale: 2),
                        CreateDate = c.DateTime(),
                        ProductId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("Product", t => t.ProductId)
                .Index(t => t.ProductId);
            
            CreateTable(
                "Salesman",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 5),
                        UserName = c.String(nullable: false, maxLength: 25),
                        PassWord = c.String(nullable: false, maxLength: 25),
                        State = c.Int(),
                        CreateDate = c.DateTime(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "InviteCode",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Code = c.String(nullable: false, maxLength: 6),
                        CreateDate = c.DateTime(),
                        SalesmanId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("Salesman", t => t.SalesmanId)
                .Index(t => t.SalesmanId);
            
            CreateTable(
                "UserInfo",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        UserName = c.String(),
                        PassWord = c.String(),
                        Ip = c.String(),
                        Email = c.String(),
                        Phone = c.String(),
                        CreateDate = c.DateTime(),
                        LoginDate = c.DateTime(),
                        Salesman_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("Salesman", t => t.Salesman_Id)
                .Index(t => t.Salesman_Id);
            
        }
        
        public override void Down()
        {
            DropIndex("UserInfo", new[] { "Salesman_Id" });
            DropIndex("InviteCode", new[] { "SalesmanId" });
            DropIndex("ProductPrice", new[] { "ProductId" });
            DropIndex("Product", new[] { "BrandId" });
            DropIndex("Product", new[] { "CategoryId" });
            DropIndex("QuoteProduct", new[] { "QuoteId" });
            DropIndex("Quote", new[] { "BrandId" });
            DropIndex("Quote", new[] { "CategoryId" });
            DropIndex("Category_Brand", new[] { "BrandId" });
            DropIndex("Category_Brand", new[] { "CategoryId" });
            DropIndex("Category", new[] { "ParentId" });
            DropIndex("News", new[] { "PNewsId" });
            DropForeignKey("UserInfo", "Salesman_Id", "Salesman");
            DropForeignKey("InviteCode", "SalesmanId", "Salesman");
            DropForeignKey("ProductPrice", "ProductId", "Product");
            DropForeignKey("Product", "BrandId", "Brand");
            DropForeignKey("Product", "CategoryId", "Category");
            DropForeignKey("QuoteProduct", "QuoteId", "Quote");
            DropForeignKey("Quote", "BrandId", "Brand");
            DropForeignKey("Quote", "CategoryId", "Category");
            DropForeignKey("Category_Brand", "BrandId", "Brand");
            DropForeignKey("Category_Brand", "CategoryId", "Category");
            DropForeignKey("Category", "ParentId", "Category");
            DropForeignKey("News", "PNewsId", "PNews");
            DropTable("UserInfo");
            DropTable("InviteCode");
            DropTable("Salesman");
            DropTable("ProductPrice");
            DropTable("Product");
            DropTable("QuoteProduct");
            DropTable("Quote");
            DropTable("Brand");
            DropTable("Category_Brand");
            DropTable("Category");
            DropTable("PNews");
            DropTable("News");
            DropTable("Company");
        }
    }
}
